import request from '@/utils/request';
import { download, toFormData, checkDownloadRes } from '@/utils/common';

/**
 * 分页查询报查询
 */
export async function pageMesReportQuerys(params) {
  const res = await request.get('/mes/mesReportQuery/list', { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部报查询
 */
export async function listMesReportQuerys(params) {
  const res = await request.get('/mes/mesReportQuery/list', { params });
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询报查询
 */
export async function getMesReportQuery(id) {
  const res = await request.get('/mes/mesReportQuery/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加报查询
 */
export async function addMesReportQuery(data) {
  const res = await request.post('/mes/mesReportQuery', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改报查询
 */
export async function updateMesReportQuery(data) {
  const res = await request.put('/mes/mesReportQuery', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除报查询
 */
export async function removeMesReportQuery(id) {
  const res = await request.delete('/mes/mesReportQuery/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除报查询
 */
export async function removeMesReportQuerys(ids) {
  const res = await request.delete('/mes/mesReportQuery/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出报查询
 */
export async function exportMesReportQuerys(params) {
  const res = await request({
    url: '/mes/mesReportQuery/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `mesReportQuery_${Date.now()}.xlsx`);
}
